In [1065]:
%matplotlib inline
import seaborn
import scipy, scipy.signal, IPython.display as ipd, matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = (13, 4)

Tuning Systems

Introduction

In the examples below, listen to each interval, and compare intervals both visually and aurally across tuning systems. Try to listen for dissonance and beat frequencies, or absence thereof.

Tuning Systems

In twelve-tone equal temperament, all twelve semitones within the octave have the same width. With this tuning system, expressed as a frequency ratio, the interval of one semitone is $2^{1/12}$. Expressed in cents, this same interval is defined to be 100 cents. Therefore, the octave has 1200 cents.

In just intonation, the frequency ratio is expressed as a fraction between two small integers, e.g. 3:2, 4:3. As a result, the higher harmonic partials between two notes will overlap, resulting in a consonant interval that is pleasing to the ear. In 5-limit just tuning, these fractions are expressed with prime factors no larger than 5, i.e. {2, 3, 5}. In 7-limit just tuning, these fractions are expressed with prime factors no larger than 7, i.e. {2, 3, 5, 7}. For example, 7:4 is a 7-limit interval, but it is not a 5-limit interval.

In Pythagorean tuning, every frequency ratio is based upon the ratio 3:2. To find that ratio, from one note in the interval, step around the Circle of Fifths until you reach the other note in the interval, multiplying (if stepping forward) or dividing (if stepping backward) by 3/2 with each step. Finally, multiply or divide by 2 enough times to return to the octave of interest.

Notebook Setup

Global parameters for this notebook:

In [1066]:
T = 5.0     # duration in seconds
fs = 24000  # sampling rate in Hertz
fcutoff = 4000 # frequency cutoff for filter

Functions used to create the sounds and figures:

In [1067]:
def simulate_tone(f0, harmonics=None):
    if harmonics is None:
        harmonics = [1]
    t = scipy.linspace(0, T, T*fs, endpoint=False)
    x = sum(v*scipy.sin(2*scipy.pi*i*f0*t) for i, v in enumerate(harmonics, 1))
    return x
In [1068]:
def filter_tone(x, fcutoff=None):
    if fcutoff is None:
        fcutoff = fs/2.0
    h = scipy.signal.firwin(55, 2*float(fcutoff)/fs)
    y = scipy.convolve(x, h)
    return y
In [1069]:
def make_double_stop(ratio, f0=440, harmonics=None):
    if harmonics is None:
        harmonics = [1]
    f1 = ratio*f0
    x0 = filter_tone(simulate_tone(f0, harmonics=harmonics), fcutoff=fcutoff)
    x1 = filter_tone(simulate_tone(f1, harmonics=harmonics), fcutoff=fcutoff)
    X0 = scipy.fft(x0)
    X1 = scipy.fft(x1)

    N = len(X0)
    f = scipy.linspace(0, fs, N, endpoint=False)
    
    plt.semilogy(f, abs(X0), marker='o', linewidth=1)
    plt.semilogy(f, abs(X1), color='r', linewidth=1)
    
    plt.xlim(xmax=(len(harmonics)+1)*(f1 if ratio > 1 else f0))
    plt.ylim(ymin=0.1)
    
    plt.xlabel('Frequency (Hz)')
    plt.legend(('f0 = %.2f Hz' % f0, 'f0 = %.2f Hz' % f1))
    
    print 'ratio:', ratio
    print 'cents:', scipy.log2(ratio)*1200
    return ipd.Audio(x0 + x1, rate=fs)

Within each section below, the intervals are provided in order of interval width from lowest to highest.

Unison

In [1070]:
make_double_stop(1)
ratio: 1
cents: 0.0
Out[1070]:

Octaves

In [1071]:
harmonics = [1.0, 0.5]

Just intonation or equal temperament, 12 semitones, 1200 cents:

In [1072]:
make_double_stop(2, harmonics=harmonics)
ratio: 2
cents: 1200.0
Out[1072]:

Pythagorean tuning, twelve steps forward on the Circle of Fifths. In Pythagorean tuning, multiply the fundamental frequency by 3/2 twelve times, and then divide by two enough times to return to the octave of interest:

$$ \left( \frac{3}{2} \right)^{12} \left( \frac{1}{2} \right)^6 = \frac{531441}{262144} \approx 2.0273 $$
In [1073]:
make_double_stop(531441.0/262144, harmonics=harmonics)
ratio: 2.02728652954
cents: 1223.46001038
Out[1073]:

The Pythagorean comma, the degree of inconsistency when trying to define a twelve-tone scale using only perfect fifths, is about 1.0136 when expressed as a frequency ratio:

$$ \left( \frac{3}{2} \right)^{12} \left( \frac{1}{2} \right)^7 = \frac{531441}{524288} \approx 1.0136 $$

Fifths

In [1074]:
harmonics = [1.0, 0.1, 0.1]

Equal temperament, seven semitones, 700 cents:

In [1075]:
make_double_stop(2**(7.0/12), harmonics=harmonics)
ratio: 1.49830707688
cents: 700.0
Out[1075]:

Just intonation or Pythagorean tuning, one step forward on the Circle of Fifths:

In [1076]:
make_double_stop(3.0/2, harmonics=harmonics)
ratio: 1.5
cents: 701.955000865
Out[1076]:

Fourths

In [1077]:
harmonics = [1.0, 0.01, 0.1, 0.1]

Just intonation or Pythagorean tuning, one step backward on the Circle of Fifths:

$$ \left( \frac{2}{3} \right) \left( \frac{2}{1} \right) = \frac{4}{3} = 1.\overline{3} $$
In [1078]:
make_double_stop(4.0/3, harmonics=harmonics)
ratio: 1.33333333333
cents: 498.044999135
Out[1078]:

Equal temperament, five semitones:

In [1079]:
make_double_stop(2**(5.0/12), harmonics=harmonics)
ratio: 1.33483985417
cents: 500.0
Out[1079]:

Major Sixths

In [1080]:
harmonics = [1.0, 0.01, 0.1, 0.01, 0.1]

Just intonation:

In [1081]:
make_double_stop(5.0/3, harmonics=harmonics)
ratio: 1.66666666667
cents: 884.358712999
Out[1081]:

Equal temperament, i.e. nine semitones:

In [1082]:
make_double_stop(2**(9.0/12), harmonics=harmonics)
ratio: 1.68179283051
cents: 900.0
Out[1082]:

Pythagorean tuning, three steps forward on the Circle of Fifths:

$$ \left( \frac{3}{2} \right)^3 \left( \frac{1}{2} \right) = \frac{27}{16} = 1.6875 $$
In [1083]:
make_double_stop(27.0/16, harmonics=harmonics)
ratio: 1.6875
cents: 905.865002596
Out[1083]:

Major Thirds

In [1084]:
harmonics = [1.0, 0.01, 0.01, 0.1, 0.1]

Just intonation:

In [1085]:
make_double_stop(5.0/4, harmonics=harmonics)
ratio: 1.25
cents: 386.313713865
Out[1085]:

Equal temperament, four semitones:

In [1086]:
make_double_stop(2**(4.0/12), harmonics=harmonics)
ratio: 1.25992104989
cents: 400.0
Out[1086]:

Pythagorean tuning, four steps forward on the Circle of Fifths:

$$ \left( \frac{3}{2} \right)^4 \left( \frac{1}{2} \right)^2 = \frac{81}{64} = 1.265625 $$
In [1087]:
make_double_stop(81.0/64, harmonics=harmonics)
ratio: 1.265625
cents: 407.820003462
Out[1087]:

Minor Thirds

In [1088]:
harmonics = [1.0, 0.01, 0.01, 0.01, 0.1, 0.1]

Pythagorean tuning, three steps backward on the Circle of Fifths:

$$ \left( \frac{2}{3} \right)^3 \left( \frac{2}{1} \right)^2 = \frac{32}{27} = 1.\overline{185} $$
In [1089]:
make_double_stop(32.0/27, harmonics=harmonics)
ratio: 1.18518518519
cents: 294.134997404
Out[1089]:

Equal temperament, three semitones:

In [1090]:
make_double_stop(2**(3.0/12), harmonics=harmonics)
ratio: 1.189207115
cents: 300.0
Out[1090]:

Just intonation:

In [1091]:
make_double_stop(6.0/5, harmonics=harmonics)
ratio: 1.2
cents: 315.641287001
Out[1091]:

Minor Sixths

In [1092]:
harmonics = [1.0, 0.001, 0.001, 0.001, 0.01, 0.001, 0.001, 0.01]

Pythagorean tuning, four steps backward on the Circle of Fifths:

$$ \left( \frac{2}{3} \right)^4 \left( \frac{2}{1} \right)^3 = \frac{128}{81} \approx 1.58 $$
In [1093]:
make_double_stop(128.0/81, harmonics=harmonics)
ratio: 1.58024691358
cents: 792.179996538
Out[1093]:

Equal temperament, eight semitones:

In [1094]:
make_double_stop(2**(8.0/12), harmonics=harmonics)
ratio: 1.58740105197
cents: 800.0
Out[1094]:

Just intonation:

In [1095]:
make_double_stop(8.0/5, harmonics=harmonics)
ratio: 1.6
cents: 813.686286135
Out[1095]:

Minor Seconds

In [1096]:
harmonics = [0.01,] * 16
harmonics[0] = 1.0
harmonics[14] = 0.1
harmonics[15] = 0.1

Just intonation:

In [1097]:
make_double_stop(16.0/15, harmonics=harmonics)
ratio: 1.06666666667
cents: 111.73128527
Out[1097]:

Equal temperament, one semitone:

In [1098]:
make_double_stop(2**(1.0/12), harmonics=harmonics)
ratio: 1.05946309436
cents: 100.0
Out[1098]:

Major Seconds

In [1099]:
harmonics = [1.0, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.1, 0.1]

Equal temperament, two semitones:

In [1100]:
make_double_stop(2**(2.0/12), harmonics=harmonics)
ratio: 1.12246204831
cents: 200.0
Out[1100]:

Just intonation or Pythagorean tuning, two steps forward on the Circle of Fifths:

$$ \left( \frac{3}{2} \right)^2 \left( \frac{1}{2} \right) = \frac{9}{8} = 1.125 $$
In [1101]:
make_double_stop(9.0/8, harmonics=harmonics)
ratio: 1.125
cents: 203.910001731
Out[1101]:

Major Sevenths

In [1102]:
harmonics = [1.0,] * 15
In [1103]:
make_double_stop(15.0/8, harmonics=harmonics)
ratio: 1.875
cents: 1088.26871473
Out[1103]:

Minor Sevenths

Harmonic seventh, or subminor seventh:

In [1104]:
make_double_stop(7.0/4)
ratio: 1.75
cents: 968.825906469
Out[1104]:

Small just minor seventh:

In [1105]:
make_double_stop(16.0/9)
ratio: 1.77777777778
cents: 996.089998269
Out[1105]:

Large just minor seventh:

In [1106]:
make_double_stop(9.0/5)
ratio: 1.8
cents: 1017.59628787
Out[1106]:

Tritone, Augmented Fourths, Diminished Fifths

Diminished fifth, Pythagorean tuning, six steps backward on the Circle of Fifths:

$$ \left( \frac{2}{3} \right)^6 \left( \frac{2}{1} \right)^4 = \frac{1024}{729} \approx 1.40466 $$
In [1107]:
make_double_stop(1024.0/729)
ratio: 1.40466392318
cents: 588.269994808
Out[1107]:

Augmented fourth:

In [1108]:
make_double_stop(45.0/32)
ratio: 1.40625
cents: 590.223715596
Out[1108]:

Equal temperament, six semitones, 600 cents:

In [1109]:
make_double_stop(2**(6.0/12))
ratio: 1.41421356237
cents: 600.0
Out[1109]:

Diminished fifth:

In [1110]:
make_double_stop(64.0/45)
ratio: 1.42222222222
cents: 609.776284404
Out[1110]:

Augmented fourth, Pythagorean tuning, six steps forward on the Circle of Fifths:

$$ \left( \frac{3}{2} \right)^6 \left( \frac{1}{2} \right)^3 = \frac{729}{512} \approx 1.4238 $$
In [1111]:
make_double_stop(729.0/512)
ratio: 1.423828125
cents: 611.730005192
Out[1111]: